<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: Author: LJQ <liujiqi@etrol.com> 
// +----------------------------------------------------------------------

namespace app\inspection\controller;

use app\common\controller\Admin;
use app\inspection\controller\api\Item as ItemApi;
use app\admin\controller\ajax\Library as LibarayAjax;
/**
 * 巡检项目管理
 * @package app\rescue
 */
class Item  extends Admin

{
    
    protected $api;
    protected $property;
    
	public function _initialize()
	{
		parent::_initialize();
		$this->api = new ItemApi();
		$this->property = new LibarayAjax();
	}
    /**
     * 首页
     * @return Json/View
     */
   	public function index() {
   	  if(IS_AJAX){
   	  	$itemList = $this->api->itemList();
   	  	return $itemList;
   	  }
   	  //重要性列表
   	  $importanceList = $this->property->getImportanceType()->getData();
   	  $this->assign('importanceList',$importanceList);
   	  //单位列表
   	  $enterpriseList = model('basic/Enterprise')->column('fullName','id');
	  $this->assign('enterpriseList',$enterpriseList);
      return $this->fetch();
 	}
 	

 	/**
 	 * 巡检项目查询
 	 * @return Json
 	 */
 	public function search() {
 		if(IS_AJAX){
 			$itemList = $this->api->search(input('keyword'),input('importance'),input('enterpriseId'));
 			return $itemList;
 		}
 	}
 	
 	
 	/**
 	 * 添加巡检项目
 	 * @return Json/View
 	 */
 	public function add(){
 		if(IS_POST){
 			$data = input('post.');
 			return $this->api->add($data);
 		}
 		//企业列表
 	  	$enterpriseList = model('basic/Enterprise')->column('fullName','id');
 		$this->assign('enterpriseList',$enterpriseList);
 		//重要性列表
 		$importanceList = $this->property->getImportanceType()->getData();
 		$this->assign('importanceList',$importanceList);
 		//周期列表
 		$cycleList = $this->property->getCycleType()->getData();
 		$this->assign('cycleList',$cycleList);
 		//参考列表
 		$referenceList = model('service/Standard')->where('typeId',2)->select();
 		$this->assign('referenceList',$referenceList);
 		return $this->fetch();
 	}
 	
 	/**
 	 * 编辑巡检项目
 	 * @param string $craftId
 	 * @return Json/View
 	 */
 	public function edit($itemId = null){
 		if(IS_POST){
 			$data = input('post.');
 			return $this->api->edit($data,$itemId);
 		}
 			//企业列表
 	  	$enterpriseList = model('basic/Enterprise')->column('fullName','id');
 		$this->assign('enterpriseList',$enterpriseList);
 		//重要性列表
 		$importanceList = $this->property->getImportanceType()->getData();
 		$this->assign('importanceList',$importanceList);
 		//周期列表
 		$cycleList = $this->property->getCycleType()->getData();
 		$this->assign('cycleList',$cycleList);
 		//参考列表
 		$referenceList = model('service/Standard')->where('typeId',2)->select();
 		$this->assign('referenceList',$referenceList);
 		$item = model('Item')->find($itemId);
 		$this->assign('info',$item);
 		return $this->fetch();
 		
 	}
 	
 	/**
 	 * 删除巡检项目
 	 * @return Json
 	 */
 	public function del($itemId = null) {
 		if(IS_AJAX){
 			return $this->api->del($itemId);
 		}
 	}
}
